package cn.zero.wechat.resp;

import java.io.Serializable;

import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.annotation.JSONField;

public class WechatError implements Serializable {

	private static final long serialVersionUID = -1151422244611825759L;

	@JSONField(name = "errcode")
	private int errorCode;

	@JSONField(name = "errmsg")
	private String errorMsg;


	public static WechatError fromJson(String json) {
		WechatError error = JSONObject.parseObject(json, WechatError.class);
		return error;
	}

	public static Builder newBuilder() {
		return new Builder();
	}

	public int getErrorCode() {
		return this.errorCode;
	}

	public void setErrorCode(int errorCode) {
		this.errorCode = errorCode;
	}

	public String getErrorMsg() {
		return this.errorMsg;
	}

	public void setErrorMsg(String errorMsg) {
		this.errorMsg = errorMsg;
	}


	@Override
	public String toString() {
		return "错误: Code=" + this.errorCode + ", Msg=" + this.errorMsg;
	}

	public static class Builder {
		private int errorCode;
		private String errorMsg;

		public Builder setErrorCode(int errorCode) {
			this.errorCode = errorCode;
			return this;
		}

		public Builder setErrorMsg(String errorMsg) {
			this.errorMsg = errorMsg;
			return this;
		}

		public WechatError build() {
			WechatError wxError = new WechatError();
			wxError.setErrorCode(this.errorCode);
			wxError.setErrorMsg(this.errorMsg);
			return wxError;
		}

	}

}
